package CRESTAURANT;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.ArrayList;
import java.sql.CallableStatement;
import java.sql.ResultSet;

/**
 * PRA 2 - EX 2. HipertensionRestRanking report. Call stored procedure.
 */
public class HipertensionRestRankingSP extends PrintList {

    /**
     * Default Constructor
     */
    public HipertensionRestRankingSP() {
	super();
    }

    /**
     * Commits the current transaction. Any error occurred is ignored.
     * 
     * @param con
     *                DB connection
     */
    private void commit(Connection con) {
	try {
	    con.commit();
	} catch (SQLException e) {
	    e.printStackTrace();
	}
    }

    /**
     * Roll backs the current transaction. Any error occurred is ignored.
     * 
     * @param con
     *                DB Connection
     */
    private void rollback(Connection con) {
	try {
	    con.rollback();
	} catch (SQLException e) {
	    e.printStackTrace();
	}
    }

    /**
     * Method to get the HipertensionRestRanking data. Call stored procedure
     * 
     * @param con
     *                Database Connection
     * @return getHipertensionRestRanking data
     * @throws SQLException
     *                 Database exception
     */
    public List getHipertensionRestRanking(Connection con) throws SQLException {

	// TODO Get Hipertension Restaurants Ranking data

	return null;
    }

    /**
     * Print Hipertension Restaurants Ranking report data for screen.
     * 
     * @param HipertensionRestRanking
     *                Hipertension Restaurants Ranking data
     * @return Verify if list printed is empty.
     */
    public boolean printHipertensionRestRankingData(
	    List HipertensionRestRankingData) {
	int[] size = { 20, 15, 15, 15, 20 };
	String[] labels = { "Restaurant", "#total_receipts",
		"#total_receipts_salt", "#total_receipts_nosalt",
		"#average_salt_in_receipts" };
	String[] attributes = { "restaurantName", "totalReceipts",
		"totalReceiptsSalt", "totalReceiptsNoSalt",
		"averageSaltInReceipts" };

	this.setAttributes(attributes);
	this.setLabels(labels);
	this.setSize(size);

	return (this.printList(HipertensionRestRankingData));
    }

    /**
     * Main method
     * 
     * @param args
     *                Method parameters
     */
    public static void main(String[] args) {

	HipertensionRestRanking rank = new HipertensionRestRanking();
	Connection con = null;

	// TODO Get a connection to the database and transaction control

	try {
	    List hipertensionRestRankingData = null;
	    hipertensionRestRankingData = rank.getHipertensionRestRanking(con);
	    boolean empty = rank
		    .printHipertensionRestRankingData(hipertensionRestRankingData);

	    if (empty)
		System.out.println("List without data.");

	} catch (Exception e1) {
	    e1.printStackTrace();

	}

	// TODO close connection to the database
	System.exit(0);
    }
}